//
// Created by vcq on 21/2/9.
//
#pragma once
#include "dbng.hpp"
struct _require_syllabus {
    int id;
    int _require_id;
    int _syllabus_id;
    int _plan_id;
    double per;
    string note;
};
REFLECTION(_require_syllabus, id, _require_id, _syllabus_id, _plan_id, per, note)

json MGetRequireSyllabus(basic_string_view<char> id, basic_string_view<char> require_id,
                         basic_string_view<char> syllabus_id, basic_string_view<char> _plan_id) {
    string sql = "select * from `_require_syllabus` where 1=1 ";
    if (!id.empty()) {
        sql += " and id =";
        sql += id;
    }
    if (!require_id.empty()) {
        sql += " and require_id =";
        sql += require_id;
    }
    if (!syllabus_id.empty()) {
        sql += " and syllabus_id =";
        sql += syllabus_id;
    }
    if (!_plan_id.empty()) {
        sql += " AND _plan_id = ";
        sql += _plan_id;
    }
    Dao dao;
    nlohmann::json article_list, ret, item;
    auto v = dao.query<_require_syllabus>(sql);
    for (auto &o : v) {
        item["id"] = o.id;
        item["per"] = o.per;
        item["_require_id"] = o._require_id;
        item["_syllabus_id"] = o._syllabus_id;
        item["_plan_id"] = o._plan_id;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}
void MAddRequireSyllabus(const struct _require_syllabus& _require_syllabus1){
    Dao dao;
    dao.update_object(_require_syllabus1);
}
void MDeleteRequireSyllabus(basic_string_view<char> id){
    MDeleteAll("_require_syllabus",id);
}